package com.huahua.graduateschoolspringboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huahua.graduateschoolspringboot.entity.R;
import com.huahua.graduateschoolspringboot.entity.param.LibraryBookPageParam;
import com.huahua.graduateschoolspringboot.entity.po.CityLibraryBook;
import com.huahua.graduateschoolspringboot.service.CityLibraryBookService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LoveHuaHua
 * @date 2023年05月07日 15:09
 * @description believe in yourself
 */
@RestController
@RequestMapping("/library")
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
public class LibraryController {

    private final CityLibraryBookService cityLibraryBookService;


    @PostMapping("/page")
    public Object page(@RequestBody LibraryBookPageParam libraryBookPageParam) {
        Page<CityLibraryBook> page = cityLibraryBookService.page(libraryBookPageParam.getPage());
        return R.successPage(page);
    }

    @PostMapping("/removeBook")
    public Object removeBook(@RequestBody CityLibraryBook cityLibraryBook) {
        cityLibraryBookService.removeById(cityLibraryBook.getId());
        return R.success();
    }
}
